package com.example.config;

import com.example.consts.RbmConsts;
import lombok.Getter;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * 队列与交换机的配置类
 * @author ..
 * @Date 2023/10/11 20:41
 */
@Configuration
public class RbmConfig {

    @Bean
    public DirectExchange directExchangeMessage(){
        return new DirectExchange(RbmConsts.MESSAGE_EX);
    }
    @Bean
    public Queue queueMessage() {
        Map<String,Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",RbmConsts.ROOTING_DEAD_EX);
        map.put("x-dead-letter-routing-key",RbmConsts.ROOTING_DEAD_QUEUE_RK);
        return new Queue(RbmConsts.MESSAGE_QUEUE,true,false,false,map);
    }

    @Bean
    public Binding bindingMessage(){
        return BindingBuilder.bind(queueMessage()).to(directExchangeMessage()).with(RbmConsts.MESSAGE_QUEUE_RK);
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(RbmConsts.ROOTING_EX);
    }
    @Bean
    public Queue queueSearch(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",RbmConsts.ROOTING_DEAD_EX);
        map.put("x-dead-letter-routing-key",RbmConsts.ROOTING_DEAD_QUEUE_RK);
        return new Queue(RbmConsts.ROOTING_DH_SEARCH,true,false,false,map);
    }
    @Bean
    public Queue queueClick(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",RbmConsts.ROOTING_DEAD_EX);
        map.put("x-dead-letter-routing-key",RbmConsts.ROOTING_DEAD_QUEUE_RK);
        return new Queue(RbmConsts.ROOTING_DH_CLICK,true,false,false,map);
    }
    @Bean
    public Binding bindSearch(){
        return BindingBuilder.bind(queueSearch()).to(directExchange()).with(RbmConsts.ROOTING_DH_SEARCH_RK);
    }

    @Bean
    public Binding bindClick(){
        return BindingBuilder.bind(queueClick()).to(directExchange()).with(RbmConsts.ROOTING_DH_CLICK_RK);
    }

    @Bean
    public DirectExchange directExchangeDead(){
        return new DirectExchange(RbmConsts.ROOTING_DEAD_EX);
    }
    @Bean
    public Queue queueDead(){
        return new Queue(RbmConsts.ROOTING_DEAD_QUEUE);
    }
    @Bean
    public Binding bindingDead(){
        return BindingBuilder.bind(queueDead()).to(directExchangeDead()).with(RbmConsts.ROOTING_DEAD_QUEUE_RK);
    }


}
